package com.hrms.common.config;

import com.baomidou.mybatisplus.annotation.IdType;
import com.baomidou.mybatisplus.autoconfigure.MybatisPlusPropertiesCustomizer;
import com.baomidou.mybatisplus.extension.plugins.MybatisPlusInterceptor;
import com.baomidou.mybatisplus.extension.plugins.inner.PaginationInnerInterceptor;
import com.hrms.common.utils.CustomIdGenerator;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.stereotype.Component;


/**
 * MybatisPlus 配置信息
 * @author kd
 */
@Configuration
@Component
public class MybatisPlusConfig {
    @Bean
    public MybatisPlusInterceptor mybatisPlusInterceptor(){

        // 初始化 MybatisPlusInterceptor 核心插件
        MybatisPlusInterceptor interceptor = new MybatisPlusInterceptor();
        // 添加自动分页插件 PaginationInnerInterceptor
        interceptor.addInnerInterceptor(new PaginationInnerInterceptor());
        // 返回
        return interceptor;
    }
    @Bean
    public MybatisPlusPropertiesCustomizer mybatisPlusPropertiesCustomizer(CustomIdGenerator idGenerator) {
        return properties -> {
            // 设置全局 ID 生成策略为 ASSIGN_ID，并绑定自定义生成器
            properties.getGlobalConfig().getDbConfig().setIdType(IdType.ASSIGN_ID);
            properties.getGlobalConfig().setIdentifierGenerator(idGenerator);
        };
    }
}

